﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListClient.aspx.cs" Inherits="WEB.APP.Modules.List.ListClient" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        var ApplyFind = function () {
            hfKeyword.setValue(txtKeyword.getValue());
            paddingBar.changePage(0);
        }
        var renderSex = function (value, idxclomn, record) {
            return value == true ? 'Male' : 'Female';
        }
        var renderClientId = function (value, idxclomn, record) {
            var string = '0000' + value.toString();
            return 'C' + string.substring(string.length - 4, string.length)
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:Hidden runat="server" ID="hfIsEdit" />
    <ext:Hidden runat="server" ID="hfIsDelete" />
    <ext:Hidden runat="server" ID="hfKeyword" />
    <ext:Hidden runat="server" ID="hdScreenDetailID" />
    <ext:Store ID="storeMain" runat="server" OnRefreshData="storeMain_OnRefreshData"
        WarningOnDirty="false">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="ClientId">
                <Fields>
                    <ext:RecordField Name="ClientId" />
                    <ext:RecordField Name="Sex" />
                    <ext:RecordField Name="SurName" />
                    <ext:RecordField Name="GivenName" />
                    <ext:RecordField Name="Email" />
                    <ext:RecordField Name="ClientType" />
                    <ext:RecordField Name="Addr1" />
                    <ext:RecordField Name="Addr2" />
                    <ext:RecordField Name="Addr3" />
                    <ext:RecordField Name="Addr4" />
                    <ext:RecordField Name="Addr5" />
                    <ext:RecordField Name="Username" />
                    <ext:RecordField Name="Password" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="50" Mode="Raw" />
        </BaseParams>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:GridPanel ID="grdMain" runat="server" StripeRows="true" TrackMouseOver="true"
                Border="false" Region="Center" StoreID="storeMain">
                <TopBar>
                    <ext:Toolbar ID="tbMain" runat="server">
                        <Items>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnAdd" runat="server" Text="New" Icon="TableAdd">
                                <Listeners>
                                    <Click Fn="AddDocument" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnDelete" runat="server" Text="Delete" Icon="TableDelete">
                                <Listeners>
                                    <Click Handler="deleteRows(#{grdMain});" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill />
                            <ext:TextField ID="txtKeyword" runat="server" EmptyText="Search">
                                <Listeners>
                                    <SpecialKey Handler="if(e.getKey() == Ext.EventObject.ENTER) { ApplyFind(); }" />
                                </Listeners>
                            </ext:TextField>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnFind" runat="server" Text="Search" Icon="Find" FormBind="true">
                                <Listeners>
                                    <Click Fn="ApplyFind" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server" DefaultSortable="false">
                    <Columns>
                        <ext:RowNumbererColumn />
                            <ext:Column ColumnID="ClientId" DataIndex="ClientId" Header="Client Id">
                                <Renderer Fn="renderClientId" />
                            </ext:Column>
                            <ext:Column ColumnID="Sex" DataIndex="Sex" Header="Sex">
                                <Renderer Fn="renderSex" />
                            </ext:Column>
                            <ext:Column ColumnID="SurName" DataIndex="SurName" Header="SurName"/>
                            <ext:Column ColumnID="GivenName" DataIndex="GivenName" Header="Given Name"/>
                            <ext:Column ColumnID="Email" DataIndex="Email" Header="Email"/>
                            <ext:Column ColumnID="ClientType" DataIndex="ClientType" Header="Client Type"/>
                            <ext:Column ColumnID="Addr1" DataIndex="Addr1" Header="Addr 1"/>
                            <ext:Column ColumnID="Addr2" DataIndex="Addr2" Header="Addr 2"/>
                            <ext:Column ColumnID="Addr3" DataIndex="Addr3" Header="Addr 3"/>
                            <ext:Column ColumnID="Addr4" DataIndex="Addr4" Header="Addr 4"/>
                            <ext:Column ColumnID="Addr5" DataIndex="Addr5" Header="Addr 5"/>
                            <ext:Column ColumnID="Username" DataIndex="Username" Header="Username"/>
                    </Columns>
                </ColumnModel>
                <KeyMap>
                    <ext:KeyBinding>
                        <Keys>
                            <ext:Key Code="DELETE" />
                        </Keys>
                        <Listeners>
                            <Event Handler="deleteRows(#{grdMain});" />
                        </Listeners>
                    </ext:KeyBinding>
                </KeyMap>
                <Listeners>
                    <RowDblClick Handler="this.getSelectionModel().selectRow(rowIndex); ViewDetail(#{grdMain});" />
                    <RowContextMenu Handler="e.preventDefault(); #{RowContextMenu}.dataRecord = this.store.getAt(rowIndex);#{RowContextMenu}.showAt(e.getXY());this.getSelectionModel().selectRow(rowIndex);" />
                </Listeners>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                </SelectionModel>
                <BottomBar>
                    <ext:PagingToolbar ID="paddingBar" StoreID="storeMain" runat="server" PageSize="50" DisplayInfo="true">
                    </ext:PagingToolbar>
                </BottomBar>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <ext:Menu ID="RowContextMenu" runat="server">
        <Items>
            <ext:MenuItem ID="mnEdit" runat="server" Text="View Detail" Icon="TableEdit">
                <Listeners>
                    <Click Handler="ViewDetail(#{grdMain});" />
                </Listeners>
            </ext:MenuItem>
            <ext:MenuItem ID="mnDelete" runat="server" Text="Delete" Icon="Delete">
                <Listeners>
                    <Click Handler="deleteRows(#{grdMain});" />
                </Listeners>
            </ext:MenuItem>
        </Items>
    </ext:Menu>
    </form>
</body>
</html>
